home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln1286.arc / BNCHMARK.ADA / DHRYSTON.ADA < prev    next >
Text File  |  1986-10-20  |  13KB  |  436 lines

  1. ---------------------------------------------------------------------------
  2. --                      "DHRYSTONE Benchmark Program"
  3. --                      -----------------------------
  4. --
  5. --
  6. --      Version: ADA/1
  7. --
  8. --      Date:    04/15/84
  9. --
  10. --      Author:  Reinhold P Weicker
  11. --
  12. --      Taken from the October 1984 issue of the Communications of the ACM.
  13. --      Source available from Mark Petersen's Alpo-Net FIDO board at
  14. --      (619) 741-3412, 300/1200/2400 8,N,1
  15. --
  16. --------------------------------------------------------------------------------
  17. --
  18. --The following program contains statements of a high-level programing
  19. --language (ADA) in a distribution considered representative:
  20. --
  21. --
  22. --  assignments                 53%
  23. --  control statements          32%
  24. --  procedure function calls    15%
  25. --
  26. --
  27. --100 statements are dynamically executed. The program is balanced with
  28. --respect to the three aspects:
  29. --
  30. --
  31. --  -statement type
  32. --  -operand type (for simple data types)
  33. --  -operand access
  34. --      operand global, local, parameter, or constant.
  35. --
  36. --The combination of these three aspects is balanced only approximately.
  37. --
  38. --The program does not compute anything meaningful, but it is syntactically
  39. --and semantically correct. All variables have a value assigned to them
  40. --before they are used as a source operand.
  41.  
  42. PACKAGE GLOBAL_DEF IS
  43.  
  44.   -- Global type definitions
  45.  
  46. type Enumeration is (Ident_1, Ident_2, Ident_3, Ident_4, Ident_5);
  47.  
  48. subtype One_To_Thirty is integer range 1..30;
  49. subtype One_To_Fifty is integer range 1..50;
  50. subtype Capital_Letter is character range 'A'..'Z';
  51.  
  52. type String_30 is array (One_To_Thirty) of character;
  53.   pragma Pack (String_30);
  54.  
  55. type Array_1_Dim_Integer is array(One_To_Fifty)of integer;
  56. type Array_2_Dim_Integer is array(One_To_Fifty,
  57.                                   One_To_Fifty)of integer;
  58.  
  59. type Record_Type(Discr:Enumeration:=Ident_1);
  60.  
  61. type Record_Pointer is access Record_Type;
  62.  
  63. type Record_Type (Discr:Enumeration:=Ident_1)is
  64.     record
  65.       Pointer_Comp:       Record_Pointer;
  66.  
  67.       case Discr is
  68.       when Ident_1=>      -- only this variant is used,
  69.                           -- but in some cases discriminant
  70.                           -- checks are necessary
  71.  
  72.        Enum_Comp:        Enumeration;
  73.        Int_Comp:         One_To_Fifty;
  74.        String_Comp:      String_30;
  75.      when Ident_2=>
  76.        Enum_Comp_2:      Enumeration;
  77.        String_comp_2:    String_30;
  78.      when others=>
  79.        Char_Comp_1,
  80.        Char_Comp_2:      Character;
  81.      end case;
  82.    end record;
  83.  
  84. end Global_Def;
  85.  
  86.  
  87.   with Global_Def;
  88.   use Global_Def;
  89.  
  90. package Pack_1 is
  91. -------------
  92.  
  93.  procedure Proc_0;
  94.  procedure Proc_1 (Pointer_Par_In:   in      Record_Pointer);
  95.  procedure Proc_2 (Int_Par_In_Out:   in out  One_To_Fifty);
  96.  procedure Proc_3 (Pointer_Par_Out:  out     Record_Pointer);
  97.  
  98.  Int_Glob:          integer;
  99.  
  100. end Pack_1;
  101.  
  102.  
  103. with Global_Def;
  104. use Global_Def;
  105.  
  106. package Pack_2 is
  107. --------------
  108.  
  109.   procedure Proc_6  (Enum_Par_In:        in      Enumeration;
  110.                      Enum_par_out:       out     Enumeration);
  111.  
  112.   procedure Proc_7  (Int_Par_In_1,
  113.                      Int_Par_In_2:       in      One_To_Fifty;
  114.                      Int_Par_Out:        out     One_To_Fifty);
  115.   procedure Proc_8  (Array_Par_In_Out_1: in out  Array_1_Dim_Integer;
  116.                      Array_Par_In_Out_2: in out  Array_2_Dim_Integer;
  117.                      Int_Par_In_1,
  118.                      Int_Par_In_2:       in      integer);
  119.   function Func_1   (Char_Par_In_1,
  120.                      Char_Par_In_2:      in      Capital_Letter)
  121.                                                    return Enumeration;
  122.  
  123.   function Func_2   (String_Par_In_1,
  124.                      String_Par_In_2:    in      String_30)
  125.                                                    return boolean;
  126.  
  127. end Pack_2;
  128.  
  129.  
  130. with Global_Def,pack_1;
  131. use Global_Def;
  132.  
  133. procedure Dhrystone is
  134. --------------
  135. begin
  136.   Pack_1.Proc_0; -- Proc_0 is actually the main program, but it is part
  137.                 -- of a package, and a program within a package can
  138.                 -- not be designated as the main program for execution.
  139.                 -- Therefore Proc_0 is activated by  a call from "Main".
  140.  
  141. end Dhrystone;
  142.  
  143. with Global_Def,Pack_2;
  144. use Global_Def;
  145.  
  146. package body Pack_1 is
  147. -----------
  148.  
  149.   Bool_Glob:         boolean;
  150.   Char_Glob_1,
  151.   Char_Glob_2:       character;
  152.   Array_Glob_1:      Array_1_dim_Integer;
  153.   Array_Glob_2:      Array_2_Dim_Integer;
  154.   Pointer_Glob,
  155.   Pointer_Glob_Next:    Record_Pointer;
  156.  
  157.   procedure Proc_4;
  158.   procedure Proc_5;
  159.  
  160. procedure Proc_0
  161. is
  162.   Int_Loc_1,
  163.   Int_Loc_2,
  164.   Int_Loc_3:     One_To_Fifty;
  165.   Char_loc:      character;
  166.   Enum_Loc:      Enumeration;
  167.   String_Loc_1,
  168.   String_Loc_2: String_30;
  169. begin
  170.  
  171.   -- Initializations
  172.  
  173.   Pack_1.Pointer_Glob_Next:=new Record_type;
  174.  
  175.   Pack_1.Pointer_glob:= new Record_Type
  176.                         '(
  177.                         Pointer_comp =>Pack_1.Pointer_Glob_next,
  178.                         Discr        =>Ident_1,
  179.                         Enum_Comp    =>Ident_3,
  180.                         Int_Comp     =>40,
  181.                         String_Comp  =>"DHRYSTONE PROGRAM, SOME STRING"
  182.                       );
  183.  
  184.   String_Loc_1 :="DHRYSTONE PROGRAM, 1'ST STRING";
  185.  
  186. -----------------
  187. -- Start timer --
  188. -----------------
  189.  
  190. for loop_count in 1 .. 10000 loop
  191.   Proc_5;
  192.   Proc_4;
  193.    --Char_Glob_1'A',Char_Glob_2='B',Bool_Glob=false
  194.   int_Loc_1:=2;
  195.   int_Loc_2:=3;
  196.   String_Loc_2:="DHRYSTONE PROGRAM, 2'ND STRING";
  197.   Enum_Loc:=Ident_2;
  198.   Bool_Glob :=not Pack_2.Func_2(String_Loc_1,String_Loc_2);
  199.    --Bool_Glob=true
  200.   while Int_Loc_1<Int_Loc_2 loop --loop body executed once
  201.    Int_Loc_3:=5*Int_Loc_1-Int_Loc_2;
  202.     --Int_Loc_3=7
  203.    Pack_2.Proc_7(Int_Loc_1,Int_Loc_2,Int_Loc_3);
  204.     -- Int_Loc_3=7
  205.    Int_Loc_1:=Int_Loc_1+1;
  206.   end loop;
  207.    --Int_Loc_1=3
  208.   Pack_2.Proc_8(Array_Glob_1,Array_Glob_2,Int_Loc_1,Int_Loc_3);
  209.    --Int_Glob=5
  210.   Proc_1(Pointer_Glob);
  211.   for Char_Index in 'A'..Char_Glob_2 loop--loop body executed twice
  212.    if Enum_Loc=Pack_2.Func_1 (Char_Index,'C')
  213.    then--not executed
  214.      Pack_2.Proc_6(Ident_1,Enum_Loc);
  215.    end if;
  216.   end loop;
  217.    --Enum_Loc=Ident_1
  218.    --Int_Loc_1=3,Int_Loc_2=3,Int_Loc_3=7
  219.   Int_Loc_3:=Int_Loc_2*Int_Loc_1;
  220.   Int_Loc_2:=Int_Loc_3/Int_Loc_1;
  221.   Int_Loc_2:=7*(Int_Loc_3-Int_Loc_2)-Int_Loc_1;
  222.   Proc_2(Int_Loc_1);
  223. end loop;
  224.  
  225. ----------------
  226. -- Stop timer --
  227. ----------------
  228.  
  229. end Proc_0;
  230.  
  231. procedure Proc_1(Pointer_Par_In:in Record_pointer)
  232. is--executed once
  233.   Next_Record:Record_Type
  234.   renames Pointer_Par_In.Pointer_Comp.all;--=Pointer_Glob_Next.all
  235. begin
  236.   Next_Record:=Pointer_Glob.all;
  237.   Pointer_Par_In.Int_Comp:=5;
  238.   Next_Record.Int_Comp:=Pointer_Par_In.Int_Comp;
  239.   Next_Record.Pointer_Comp:=Pointer_Par_In.Pointer_comp;
  240.   Proc_3(Next_Record.Pointer_Comp);
  241.     -- Next_Record.Pointer_Comp=Pointer_Glob.Pointer_Comp=Pointer_Glob_Next
  242.   if Next_Record.Discr=Ident_1
  243.   then -- executed
  244.     Next_Record.Int_Comp:=6;
  245.     Pack_2.Proc_6(Pointer_Par_In.Enum_Comp,Next_Record.Enum_Comp);
  246.     Next_Record.Pointer_Comp:=Pointer_Glob.Pointer_Comp;
  247.     Pack_2.Proc_7(Next_record.Int_Comp,10,Next_Record.Int_comp);
  248.   else -- not executed
  249.     Pointer_Par_In.all:=Next_record;
  250.   end if;
  251. end Proc_1;
  252.  
  253. procedure Proc_2(Int_par_In_Out: in out One_To_Fifty)
  254. is -- executed once
  255.    -- In_Par_In_Out=3,becomes 7
  256.   Int_Loc:One_To_Fifty;
  257.   Enum_Loc:Enumeration;
  258. begin
  259.   Int_Loc:=Int_Par_In_Out+10;
  260.   loop -- executed once
  261.     if Char_Glob_1='A'
  262.     then -- executed
  263.      Int_Loc:=Int_Loc-1;
  264.      Int_Par_In_Out:=Int_Loc-Int_Glob;
  265.      Enum_Loc:=Ident_1;
  266.    end if;
  267.   exit when Enum_Loc=Ident_1;  -- true
  268.   end loop;
  269. end Proc_2;
  270.  
  271. procedure Proc_3(Pointer_Par_Out:out Record_Pointer)
  272. is -- executed once
  273.    -- Pointer_Par_Out becomes Pointer_Glob
  274. begin
  275.   if Pointer_Glob/=null
  276.   then -- executed
  277.    Pointer_Par_Out:=Pointer_Glob.Pointer_Comp;
  278.   else -- not executed
  279.    Int_Glob:=100;
  280.   end if;
  281.   Pack_2.Proc_7(10,Int_Glob,Pointer_Glob.Int_Comp);
  282. end Proc_3;
  283.  
  284. procedure Proc_4 -- without parameters
  285. is -- executed once
  286.   Bool_Loc:boolean;
  287. begin
  288.   Bool_Loc:=Char_Glob_1='A';
  289.   Bool_Loc:=Bool_Loc or Bool_Glob;
  290.   Char_Glob_2:='B';
  291. end Proc_4;
  292.  
  293. procedure Proc_5--without parameters
  294. is--executed once
  295. begin
  296.   Char_Glob_1:='A';
  297.   Bool_Glob:=false;
  298. end Proc_5;
  299.  
  300. end Pack_1;
  301.  
  302. with Global_Def,Pack_1;
  303. use Global_Def;
  304.  
  305. package body Pack_2 is
  306. ------------------
  307. function Func_3 (Enum_Par_In:in Enumeration) return boolean;
  308.         -- forward declaration
  309.  
  310. procedure Proc_6 (Enum_Par_In:   in  Enumeration;
  311.                   Enum_Par_out:  out Enumeration)
  312. is -- executed once
  313.    -- Enum_Par_In=Ident_3,Enum_Par_Out becomes Ident_2
  314. begin
  315.   Enum_Par_Out:=Enum_par_In;
  316.   if not Func_3(Enum_Par_in)
  317.   then -- not executed
  318.     Enum_Par_Out:=Ident_4;
  319.   end if;
  320.   case Enum_Par_In is
  321.    when Ident_1=>Enum_Par_out:=Ident_1;
  322.    when Ident_2=>if Pack_1.Int_Glob>100
  323.                  then Enum_Par_Out:=Ident_1;
  324.                  else Enum_Par_Out:=Ident_4;
  325.                  end if;
  326.    when Ident_3=>Enum_Par_Out:=Ident_2; -- executed
  327.    when Ident_4=>null;
  328.    when Ident_5=>Enum_Par_Out:=Ident_3;
  329.    end case;
  330.   end Proc_6;
  331.   procedure Proc_7(Int_par_In_1,
  332.                    Int_Par_In_2: in  One_To_Fifty;
  333.                    Int_Par_Out:  out One_To_Fifty)
  334.   is -- executed three times
  335.      -- first call: Int_Par_In_1=2,Int_Par_In_2=3,
  336.      --             Int_Par_Out becomes 7
  337.      -- second call:Int_Par_In_1=6,Int_Par_In_2=10,
  338.      --             Int_Par_Out becomes 18
  339.      -- third call: Int_Par_In_1=10,Int_Par_In_2=5,
  340.      --             Int_Par_Out becomes 17
  341.   Int_Loc:One_To_Fifty;
  342. begin
  343.   Int_Loc:=Int_Par_In_1+2;
  344.   Int_Par_Out:=Int_Par_In_2+Int_Loc;
  345. end Proc_7;
  346. procedure Proc_8(Array_Par_In_Out_1:in out Array_1_Dim_Integer;
  347.                  Array_Par_In_Out_2:in out Array_2_Dim_Integer;
  348.                  Int_Par_In_1,
  349.                  Int_Par_In_2:      in     integer)
  350. is -- executed once
  351.    -- Int_Par_In_1=3
  352.    -- Int_Par_In_2=7
  353.  Int_loc:One_To_Fifty;
  354. begin
  355.  Int_Loc:=Int_Par_In_1+5;
  356.  Array_Par_In_Out_1(Int_Loc):=Int_Par_In_2;
  357.  Array_Par_In_Out_1(Int_Loc+1):=
  358.                         Array_Par_In_Out_1(Int_Loc);
  359.  Array_Par_In_Out_1(Int_Loc+30):=Int_Loc;
  360.  for Int_Index in Int_Loc..Int_Loc+1 loop -- loop body executed twice
  361.    Array_Par_In_Out_2(Int_Loc,Int_Index):=Int_Loc;
  362.  end loop;
  363.  Array_Par_In_Out_2(Int_Loc,Int_Loc-1):=
  364.                         Array_Par_In_out_2(Int_Loc,Int_Loc-1)+1;
  365.  Array_Par_In_Out_2(Int_Loc+20,Int_Loc):=
  366.                         Array_Par_In_Out_1(Int_Loc);
  367.  Pack_1.Int_Glob:=5;
  368. end Proc_8;
  369.  
  370. function Func_1(Char_Par_In_1,
  371.                 Char_Par_In_2:in Capital_Letter)
  372.                                                return Enumeration
  373. is -- executed three times,returns Ident_1 each time
  374.    -- first call:  Char_Par_In_1='H', Char_Par_In_2='R'
  375.    -- second call: Char_Par_In_1='A', Char_Par_In_2='C'
  376.    -- third call : Char_Par_In_1='B', Char_Par_In_2='C'
  377.  Char_Loc_1,Char_Loc_2:Capital_Letter;
  378. begin
  379.   Char_Loc_1:=Char_Par_In_1;
  380.   Char_Loc_2:=Char_Loc_1;
  381.   if Char_Loc_2/=Char_Par_In_2
  382.   then--executed
  383.     return Ident_1;
  384.   else--not executed
  385.     return Ident_2;
  386.   end if;
  387.   end Func_1;
  388. function Func_2(String_Par_In_1,
  389.                 String_Par_In_2:in String_30)return boolean
  390. is -- executed once,returns false
  391.    -- String_Par_In_1="DHRYSTONE, 1'ST STRING"
  392.    -- String_Par_IN_2="DHRYSTONE, 2'ND STRING"
  393.    Int_Loc:  One_To_Thirty;
  394.    Char_Loc: Capital_Letter;
  395. begin
  396.   Int_Loc:=2;
  397.   while Int_Loc<=2 loop -- loop body executed once
  398.     if Func_1(String_Par_In_1(Int_Loc),
  399.               String_Par_In_2(Int_Loc+1))=Ident_1
  400.     then-- executed
  401.      Char_Loc:='A';
  402.      Int_Loc:=Int_Loc+1;
  403.     end if;
  404. end loop;
  405. if Char_Loc>='W' and Char_Loc<'Z'
  406. then-- not executed
  407.    Int_Loc:=7;
  408. end if;
  409. if Char_Loc='X'
  410. then-- not executed
  411.   return true;
  412. else -- executed
  413.   if String_Par_In_1>String_Par_In_2
  414.   then -- executed
  415.     Int_Loc:=Int_Loc+7;
  416.     return true;
  417.  else -- executed
  418.     return false;
  419.    end if;
  420.   end if;
  421. end Func_2;
  422.  
  423. function Func_3(Enum_Par_In:in Enumeration)return boolean
  424. is -- executed once,returns true
  425.    -- Enum_Par_In=Ident_3
  426.  Enum_Loc:Enumeration;
  427. begin
  428.  Enum_Loc:=Enum_Par_In;
  429.  if Enum_Loc=Ident_3
  430.  then -- executed
  431.    return true;
  432.  end if;
  433. end Func_3;
  434.  
  435. end Pack_2;
  436.